module counter8(out, cout, data, load, cin, clk);

	output[7:0] out;
	output cout;
	input[7:0] data;
	input load, cin, clk;
	reg[7:0] out;
	always @(posedge clk)
		begin
			if(load)
				out <= data;				//同步预制数据
			else
				out <= out + 1 + cin;	//加1计数
		end
	assign cout = &out&cin;				//若out为8'hFF, cin为1, 则cout为1
endmodule
